//
//  ZChangePasswordController.m
//  NewProject
//
//  Created by Apple on 2018/5/19.
//  Copyright © 2018年 chenIos. All rights reserved.
//

#import "ZChangePasswordController.h"

@interface ZChangePasswordController ()

@end

@implementation ZChangePasswordController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)initUI{
    for (UIView *segmentView in self.segmentViews) {
        segmentView.backgroundColor = COLOR_LIGHT_GRAY;
    }
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:Z_Location(@"done") style:(UIBarButtonItemStylePlain) target:self action:@selector(changePasswordAction)];
    self.current_password_tf.placeholder = Z_Location(@"currentPassword");
    self.fresh_password_tf.placeholder = Z_Location(@"newPassword");
    self.repeat_password_tf.placeholder = Z_Location(@"repeatPassword");
}
- (void)changePasswordAction{
    if ([self.current_password_tf.text isEqualToString:self.accout.password]) {
        if ([self.fresh_password_tf.text isEqualToString:self.repeat_password_tf.text]) {
            
            [ZDBManager changePassword:self.fresh_password_tf.text wallet:self.accout.walletAdress completion:^(BOOL isSuccess) {
                if (isSuccess) {
                    self.accout.password = self.fresh_password_tf.text;
                    [ZProgressManager showSuccess:Z_Location(@"changePasswordSuccessfully")];
                    [self.navigationController popViewControllerAnimated:YES];
                }else
                {
                    [ZProgressManager showError:Z_Location(@"pwd_inconformity")];
                }
            }];
            
        }else
        {
            [ZProgressManager showError:Z_Location(@"pwd_inconformity")];
        }
    }else
    {
        [ZProgressManager showError:Z_Location(@"passWordIncorrect")];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = Z_Location(@"changePassword");
    [self initUI];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
